package com.web.servlet;

import com.bean.Goods;
import com.service.GoodsService;
import com.service.impl.GoodsServiceImpl;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.util.List;

/**
 * 获取全部商品
 */
@WebServlet("/goods")
public class GoodServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        GoodsService goodsService = new GoodsServiceImpl();
        //获得商品列表
        List<Goods> goods = goodsService.seAll();
        //将商品列表保存到session中
        request.getSession().setAttribute("goods",goods);
        response.sendRedirect("dataList.jsp");
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request, response);
    }
}
